#include<iostream>
#include<vector>

using namespace std;
const int N = 15;
int col[N * 2] , st1[N * 2] , st2[N * 2];
vector<int>path;
int n;
int ret;
void dfs(int x)
{
    if(x > n)
    {
        ret++;
        if(ret <= 3)
        {
            for(auto e : path) cout << e << " ";
            cout << endl;
        }
        return;
    }

    for(int y = 1;y <= n;y ++)
    {
        if(col[y] || st1[y - x + n] || st2[y + x]) continue;

        col[y] = true , st1[y - x + n] = true , st2[y + x] = true;
        path.push_back(y);
        dfs(x + 1);

        col[y] = false , st1[y - x + n] = false;
        st2[y + x] = false;
        path.pop_back();
    }
}
int main()
{
    cin >> n;
    dfs(1);
    cout << ret << endl;
    return 0;
}